﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
using Sandbox.Main;
using Sandbox.Editor;
using Sandbox.Game;

namespace Sandbox
{
	/// <summary>
	/// Interaction logic for App.xaml
	/// </summary>
	public partial class App : Application
	{
		private void Application_Startup(object sender, StartupEventArgs e)
		{
			ParseStartupArguments(e.Args);

			// Create main application window, starting minimized if specified
			if (IsEditor)
			{
				Client = new EditorClient();
				Client.Initialize();
				EditorWindow editorWindow = new EditorWindow();
				editorWindow.Show();
				MainWindow = editorWindow;
			}
			else
			{
				Client = new GameClient();
				Client.Initialize();
				GameWindow gameWindow = new GameWindow();
				GameClient.GameWindow = gameWindow;
				gameWindow.Show();
				MainWindow = gameWindow;
			}			
		}


		public static Client Client
		{
			get;
			private set;
		}

		public static GameClient GameClient
		{
			get { return Client as GameClient; }
		}

		public static bool IsEditor
		{
			get;
			private set;
		}

		private void ParseStartupArguments(string[] args)
		{
			foreach (string arg in args)
			{
				if (arg.Equals("-editor", StringComparison.OrdinalIgnoreCase))
					IsEditor = true;
			}
		}
	}
}
